import axios from 'axios'
import {getToken} from '@/utils/token.js'
import { Message } from 'element-ui'

const service = axios.create({
   baseURL:'/api',
   timeout:5000,
})


// 请求拦截器
service.interceptors.request.use(config=>{
  //config.headers.Authorization  = getToken('token')
  config.headers['token']  = getToken('token')
  return config;
},err=>{
   return Promise.reject(err)
})



// 响应拦截器
service.interceptors.response.use(response=>{
  let { status,message}  = response.data;
  if(status !==200){
     Message({message:message || 'error',type:'warning'})
  }
  return response;
},err=>{
  return Promise.reject(err)
})

export default service;